#pragma once

#define SQRT_MAGIC_F 0x5f3759df
#define SQRT_MAGIC_D 0x5fe6ec85e7de30da

inline float FastSqrt_5(const float x)  
{
	union {int i;float x;}u;
	u.x = x;
	u.i = (1<<29) + (u.i >> 1) - (1<<22); 
	return u.x;
}

inline float FastSqrt_2(const float x)
{
	const float xhalf = 0.5f*x;
	union 
	{float x;int i;} u;// get bits for floating value
	u.x = x;
	u.i = SQRT_MAGIC_F - (u.i >> 1);  // gives initial guess y0
	return (u.x*(1.5f - xhalf*u.x*u.x)) * x;// Newton step, repeating increases accuracy
}
